const rp = require('request-promise');

module.exports = {
  Post(url,data){
    let { ctx } = this;
    let options = {
      method:'POST',
      uri: 'http://'+url,
      form: data,
      json: true,
      headers:{
        token:ctx.session.token
      }
    };
    if(!ctx.session.token) delete options.headers;
    return rp(options);
  },
  Get(url){
    let { ctx } = this;
    let options = {
      method:'GET',
      uri: 'http://'+url,
      json: true,
      headers:{
        token:ctx.session.token
      }
    };
    if(!ctx.session.token) delete options.headers;
    return rp(options)
  }
};
